package Login;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.Timer;

public class LoginPane extends JPanel implements ActionListener, MouseListener, MouseMotionListener {
	private CardLayout cards;
	private int nextFrame;
	private JPanel parent;
	private BufferedImage bg;
	private Button back, login;
	private Timer time;
	
	public LoginPane(JPanel parent, int n, CardLayout cards, String filename){
		this.cards=cards;
		this.nextFrame=n;
		this.parent=parent;
		this.setLayout(null);
		back =  new Button("images/back.png", "images/back2.png", "images/back2a.png");
		login = new Button("images/l"+n+".png", "images/l"+n+"a.png", "images/l"+n+".png");
		
		try {
			this.bg=ImageIO.read(new File(filename));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.print("Image not found");
			e.printStackTrace();
		}
		time = new Timer(300, this);
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		
		JLabel usrname = new JLabel("Username:");
		JLabel passwrd = new JLabel("Password:");
		JTextField user = new JTextField();
		JPasswordField pass =new JPasswordField();
		
		Font font = new Font("Calibri", Font.PLAIN, 20);
		//usrname.setLocation(100, 100);
		usrname.setBounds(240, 115, 165, 27);
	    passwrd.setBounds(240, 175, 165, 27);
		
	    usrname.setFont(font);
	    passwrd.setFont(font);
	    
	    user.setBounds(250, 145, 190, 27);
        pass.setBounds(250, 205, 190, 27);
	
        
		this.add(usrname);
		this.add(passwrd);
		this.add(user);
		this.add(pass);
		
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		repaint();
	}
	public void paint(Graphics g){
		super.paint(g);
		Graphics2D g2D = (Graphics2D)g;

		time.start();
		g2D.drawImage(bg, 25, 60, null);
		g2D.drawImage(back.getCurImg(), 10, 10, null);
		g2D.drawImage(login.getCurImg(), 324, 308, null);
		
	}
	@Override
	public void mouseDragged(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent m) {
		// TODO Auto-generated method stub
		if (m.getX() >= 12&& m.getX()<=102&&m.getY()>=11&&m.getY()<=42){//within the boundaries of back
			back.setCurImg(1);
		}
		else{
			back.setCurImg(0);
		}
	}

	@Override
	public void mouseClicked(MouseEvent m) {
		// TODO Auto-generated method stub
		System.out.print(m.getX() + " "+m.getY());
	}

	@Override
	public void mouseEntered(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent m) {
		// TODO Auto-generated method stub
		
	}

	

}
